package GUI.Cocina;

import java.rmi.RemoteException;

import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;

import sale.entities.OrderVO;
import sale.exceptions.NoSalesException;
import service.ServiceFacade;
import service.article.exceptions.ProxyException;
import service.sale.interfaces.SaleProxyMgt;
import GUI.Administracion.Exceptions.ExcepcionesMenuVentas;

public class MenuCocina extends Dialog {

	protected Object result;
	protected Shell shell;

	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public MenuCocina(Shell parent, int style) {
		super(parent, style);
		setText("SWT Dialog");
	}

	/**
	 * Open the dialog.
	 * @return the result
	 */
	public Object open() {
		createContents();
		shell.open();
		shell.layout();
		Display display = getParent().getDisplay();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		return result;
	}

	/**
	 * Create contents of the dialog.
	 */
	private void createContents() {
		shell = new Shell(getParent(), getStyle());
		shell.setSize(450, 300);
		shell.setText(getText());
		System.out.println("toy aca");
		
		Button button = new Button(shell, SWT.NONE);
		button.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				SaleProxyMgt sales = ServiceFacade.getInstance().getSaleProxyMgt();
				try {
					OrderVO [] ordenes = sales.getOpenOrders();
				} catch (RemoteException e2) {
					ExcepcionesMenuVentas ventana = new ExcepcionesMenuVentas (shell, shell.getStyle(), "Error de Conexion con el Servidor");
					ventana.open();
					shell.dispose();
					e2.printStackTrace();
				} catch (ProxyException e2) {
					ExcepcionesMenuVentas ventana = new ExcepcionesMenuVentas (shell, shell.getStyle(), "Error de Conexion con el Servidor");
					ventana.open();
					shell.dispose();
					e2.printStackTrace();
				}
				OrdenesAbiertas o = new OrdenesAbiertas (shell, shell.getStyle());
				shell.setVisible(false);
				try {
					o.open();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (ProxyException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (NoSalesException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			}
		});
		button.setText("Ver Ordenes Abiertas");
		button.setBounds(137, 62, 188, 33);
		
		Button button_1 = new Button(shell, SWT.NONE);
		button_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				IngredienteFaltante f = new IngredienteFaltante(shell, shell.getStyle());
				f.open();
			}
		});
		button_1.setText("Ingresar Articulo Faltante");
		button_1.setBounds(137, 172, 188, 33);
		
		Button button_2 = new Button(shell, SWT.NONE);
		button_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				AgregarAlStock a = new AgregarAlStock (shell, shell.getStyle());
				a.open();
			}
		});
		button_2.setText("Reponer Ingredientes");
		button_2.setBounds(137, 114, 188, 33);

	}
}
